<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      div {
        width: 300px;
        height: 300px;
        border: 2px solid red;
        margin: 0 auto;
        line-height: 100px;
        font-size: 50px;
      }
    </style>
  </head>
  <body>
    <div id="box">王增杨</div>
    <script>
      var arr = [
        "王增杨1",
        "王增杨2",
        "王增杨3",
        "王增杨4",
        "王增杨5",
        "王增杨6",
        "王增杨7",
        "王增杨8",
        "王增杨9",
        "王增杨10",
        "王增杨11",
        "李诚豪",
        "叶家佐",
      ];
      // console.log(arr[2]);

      var t = window.setInterval(function () {
        box.innerHTML = arr[parseInt(Math.random() * arr.length)];
        //随机获取到数组的索引,把这个索引对应的值显示到div里面去
      }, 10);
      var bool = true;//标记
      document.onclick = function () {
        if (bool) {
          window.clearInterval(t);//关闭定时器
          bool=false;//改变标记
        } else {
          t = window.setInterval(function () {
            box.innerHTML = arr[parseInt(Math.random() * arr.length)];
          }, 10);
          bool=true
        }
      };
    </script>
  </body>
</html>
